<?php
/*IMPORTANT: 注意检查文件字符集是否为UTF-8*/
$c = "";
if(@$_GET['channel'])
{
	$c = $_GET['channel'];
}
switch ($c)
{
	case "zabbix":
		header("Content-type: application/xml");
		$json = file_get_contents('./zabbix_rss.json');
		$json = json_decode($json);
		$arrItems = array();
		foreach($json as $zabbix)
		{
			$link = "";
			switch ($zabbix->prefix)
			{
				case "yl_":
					$link = "https://zabbix.service.chinanetcloud.com/";
					break;
				case "190_":
					$link = "http://172.16.10.190/zabbix/";
					break;
			}
			for($i=0;$i<count($zabbix->data->eventids);++$i)
			{
				array_push($arrItems,array("id"=>$zabbix->data->eventids[$i],"event"=>$zabbix->data->events[$i],"link"=>$link));
			}
		}
		$xml = "";
		foreach ($arrItems as $item)
		{
			$xml .= '<item id="'.$item['id'].'">
<title><![CDATA['.$item['event'][0].':'.$item['event'][1].']]></title>
<link>'.$item['link'].'?'.$item['id'].'</link>
<description><![CDATA['.$item['event'][1].'(Acked:'.$item['event'][3].', Duration: '.$item['event'][2].', '.date('Y-m-d H:i:s').')'.']]></description>
<pubDate>'.date('Y-m-d H:i:s',mktime()-28800).'</pubDate>
<ttl>20</ttl>
</item>'."\r\n";
		}
		if ($xml=="")
		{
			$xml .= '<item id="0">
<title><![CDATA[No alert]]></title>
<link></link>
<description><![CDATA[No alert]]></description>
<pubDate>'.date('Y-m-d H:i:s',mktime()-28800).'</pubDate>
<ttl>10</ttl>
</item>'."\r\n";
		}
		echo '<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Kanbix Zabbix Monitor</title>
<link>http://114.80.151.71/kanbix/</link>
<description>看看系统监控平台</description>
<pubDate>'.date('Y-m-d H:i:s',mktime()-28800).'</pubDate>
<lastBuildDate>'.date('Y-m-d H:i:s',mktime()-28800).'</lastBuildDate>
'.$xml.'</channel>
</rss>';
		break;
	default:
		break;
}
?>